package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.ChooseAddressPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.ChooseAddressView
import com.weetop.cfw.bean.AllSubSiteListBean
import com.weetop.cfw.bean.HotSitesBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.home_page.activity.ChooseAddressActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class ChooseAddressPresenterImp(var chooseAddressView: ChooseAddressView? = null): ChooseAddressPresenter {

    /**
     * 获取所有站点数据
     */
    override fun getAllSitesListData(chooseAddressActivity: ChooseAddressActivity) {
        chooseAddressActivity.showLoadingDialog(chooseAddressActivity,"正在拉取所有站点数据...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getAllSubSiteListData(),chooseAddressActivity,object:RxJavaCallBack<AllSubSiteListBean>(){
            override fun onSuccess(t: AllSubSiteListBean?) {
                chooseAddressActivity.dismissLoadingDialog()
                chooseAddressView?.allSubSitesGetSuccess(t)
            }

            override fun onRequestError(t: AllSubSiteListBean?) {
                super.onRequestError(t)
                chooseAddressActivity.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                chooseAddressActivity.dismissLoadingDialog()
            }
        })
    }

    /**
     * 获取热门城市信息
     */
    override fun getHotSitesData(chooseAddressActivity: ChooseAddressActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getHotSitesData(),chooseAddressActivity,object:RxJavaCallBack<HotSitesBean>(){
            override fun onSuccess(t: HotSitesBean?) {
                chooseAddressView?.hotSitesGetSuccess(t)
            }
        })
    }


    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        chooseAddressView = baseView as? ChooseAddressView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        chooseAddressView = null
    }
}